package kit.msc.gui;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

import kit.msc.Listener.ShortcutDispatcher;
import kit.msc.utility.CardLayoutManager;
import kit.msc.utility.Preference;
import kit.msc.utility.ScreenSize;

public class MainFrm extends JFrame {

	/**
   *
   */
	private static final long serialVersionUID = 1L;

	private JPanel rootPanel;
	private ScreenSize screenSize;
	private TablePanel tablePanel;
	private ConfigPanel configPanel;

	public MainFrm(String cardString) {
		super(Preference.get("tableViewName", "TimeTable"));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		screenSize = new ScreenSize();
		this.setMaximumSize(screenSize.getScaledDimension(0.9));
		this.setPreferredSize(screenSize.getScaledDimension(0.9));
		this.setMinimumSize(new Dimension(Preference.getInt("tableViewMinWidth", 500), Preference.getInt("tableViewMinHeight", 300)));

		this.setUndecorated(true);

		rootPanel = new JPanel(new CardLayout());
		rootPanel.setBackground(Color.WHITE);

		tablePanel = new TablePanel();
		rootPanel.add(tablePanel, CardLayoutManager.TableCard);
		configPanel = new ConfigPanel();
		rootPanel.add(configPanel, CardLayoutManager.ConfigCard);

		this.setContentPane(rootPanel);

		pack();
		this.setLocationRelativeTo(null);

		new ShortcutDispatcher();

		if (cardString == null) {
			CardLayoutManager.switchCard(rootPanel, this, CardLayoutManager.TableCard);
		} else {
			CardLayoutManager.switchCard(rootPanel, this, cardString);
		}

	}
}
